﻿
// MFCLearn02View.cpp: CMFCLearn02View 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MFCLearn02.h"
#endif

#include "MFCLearn02Doc.h"
#include "MFCLearn02View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCLearn02View

IMPLEMENT_DYNCREATE(CMFCLearn02View, CView)

BEGIN_MESSAGE_MAP(CMFCLearn02View, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMFCLearn02View::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// CMFCLearn02View 构造/析构

CMFCLearn02View::CMFCLearn02View() noexcept
{
	// TODO: 在此处添加构造代码

}

CMFCLearn02View::~CMFCLearn02View()
{
}

BOOL CMFCLearn02View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CMFCLearn02View 绘图

void CMFCLearn02View::OnDraw(CDC* /*pDC*/)
{
	CMFCLearn02Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码
}


// CMFCLearn02View 打印


void CMFCLearn02View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CMFCLearn02View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMFCLearn02View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMFCLearn02View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}

void CMFCLearn02View::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CMFCLearn02View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CMFCLearn02View 诊断

#ifdef _DEBUG
void CMFCLearn02View::AssertValid() const
{
	CView::AssertValid();
}

void CMFCLearn02View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCLearn02Doc* CMFCLearn02View::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCLearn02Doc)));
	return (CMFCLearn02Doc*)m_pDocument;
}
#endif //_DEBUG


// CMFCLearn02View 消息处理程序


void CMFCLearn02View::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CView::OnLButtonDown(nFlags, point);

	//MessageBox(NULL, L"我是中国人", MB_OK | MB_RETRYCANCEL);
	//MessageBox(NULL, TEXT("Hello world."), TEXT("Hello"), MB_ICONQUESTION | MB_ABORTRETRYIGNORE);
	CClientDC cdc(this);
	CPen newPen, greenPen;
	CPen* pOldPen;
	//创建画笔
	newPen.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
	greenPen.CreatePen(PS_SOLID, 2, RGB(0, 255, 0));
	//选择画笔
	pOldPen = cdc.SelectObject(&newPen);
	//画圆
	//参数1: nLeftRect  指定限定矩形左上角的X坐标
	//参数2：nTopRect   指定限定矩形左上角的Y坐标
	//参数3：nRightRect     指定限定矩形右下角的X坐标
	//参数4：nBottomRect  指定限定矩形右下角的Y坐标
	cdc.Ellipse(point.x - 50, point.y - 50, point.x + 50, point.y + 50);

	cdc.TextOutW(point.x, point.y, L"我是中国人");

	cdc.SelectObject(&greenPen);
	//移动到鼠标点击的位置
	cdc.MoveTo(point.x, point.y);


	//向东南方向画一条线
	cdc.LineTo(point.x + 100, point.y + 100);


	//增加一条注释，我是中国人
		
	//还原画笔
	cdc.SelectObject(pOldPen);
}
